package cn.lizemin.share.version0.entity;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lzm
 * @version 1.0
 * @description: 带有图件缓存的工厂类
 * @date 2022/5/19 10:04
 */
public class TileFactory {

    private Map<String, Drawable> images;//图库

    public TileFactory() {
        this.images = new HashMap<String,Drawable>();
    }

    public Drawable getDrawable(String image) {
//        如果不包含图件，则将其放到缓存中
        if (!images.containsKey(image)) {
//            判断是哪种图件
            switch (image) {
                case "河流":
                    images.put(image, new River());
                    break;
                case "草地":
                    images.put(image, new Grass());
                    break;
                case "道路":
                    images.put(image, new Road());
                    break;
                case "房屋":
                    images.put(image, new House());
                    break;
            }

        }

//        至此，缓存池中必然有图件，直接取得并返回
        return images.get(image);
    }

}
